package com.vast.admin.controller;

import cn.hutool.core.date.DateUtil;
import com.vast.admin.annotation.UseToken;
import com.vast.admin.api.CietacApi;
import com.vast.admin.api.cietac.entity.ProjectDetail;
import com.vast.admin.api.cietac.entity.ProjectDicts;
import com.vast.admin.entity.bo.ArbitrationProjectAddBo;
import com.vast.admin.entity.bo.ArbitrationProjectEditBo;
import com.vast.admin.entity.bo.ArbitrationProjectQueryBo;
import com.vast.admin.entity.vo.ArbitrationProjectVo;
import com.vast.admin.service.IArbitrationProjectService;
import com.vast.common.core.domain.AjaxResult;
import com.vast.common.core.domain.Result;
import com.vast.common.core.domain.entity.SysUser;
import com.vast.common.utils.SecurityUtils;
import com.vast.system.core.controller.BaseController;
import com.vast.system.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;
import java.util.List;

/**
 * 仲裁项目Controller
 *
 * @author ruoyi
 * @date 2021-05-10
 */
@Api(value = "仲裁项目控制器", tags = {"仲裁项目管理"})
@RestController
@RequestMapping("/manager/arbitration/project")
public class ArbitrationProjectController extends BaseController {

    @Autowired
    private IArbitrationProjectService iArbitrationProjectService;

    @Autowired
    private CietacApi cietacApi;

    /**
     * 查询仲裁项目列表
     */
    @ApiOperation("查询仲裁项目列表")
    @GetMapping("/list")
    public TableDataInfo<ArbitrationProjectVo> list(ArbitrationProjectQueryBo bo) {
        startPage();
		SysUser manager = SecurityUtils.getLoginUser().getUser();
        List<ArbitrationProjectVo> list = iArbitrationProjectService.queryList(bo, manager);
        return getDataTable(list);
    }

    /**
     * 获取仲裁项目详细信息
     */
    @ApiOperation("获取仲裁项目详细信息")
    @GetMapping("/{id}")
    public AjaxResult<ArbitrationProjectVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iArbitrationProjectService.queryById(id));
    }

    /**
     * 新增仲裁项目
     */
    @ApiOperation("新增仲裁项目")
    @PostMapping("/createProject")
    @UseToken
    public AjaxResult<Void> add(ArbitrationProjectAddBo bo) {
		SysUser manager = SecurityUtils.getLoginUser().getUser();
        bo.setCreateBy(manager.getUserId());
        bo.setCreateTime(DateUtil.date());
        bo.setUpdateBy(manager.getUserId());
        bo.setUpdateTime(DateUtil.date());
        bo.setValid(1);
        bo.setStatus("1");
        return toAjax(iArbitrationProjectService.insertByAddBo(manager.getMobile(),bo) ? 1 : 0);
    }

    /**
     * 修改仲裁项目
     */
    @ApiOperation("修改仲裁项目")
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody ArbitrationProjectEditBo bo) {
        return toAjax(iArbitrationProjectService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除仲裁项目
     */
    @ApiOperation("删除仲裁项目")
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@PathVariable Long[] ids) {
        return toAjax(iArbitrationProjectService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }

    /**
     * 获取立项数据字典
     */
    @ApiOperation("获取立项数据字典")
    @GetMapping("/getProjectDicts")
    public Result<ProjectDicts> getProjectDictParams(@RequestHeader String User) {
        return cietacApi.getProjectParams(User);
    }

    /**
     * 通过项目id获取项目详情
     * @return
     */
    @ApiOperation("通过项目id获取项目详情")
    @GetMapping(value = "/projectDetailById/{projectId}")
    @UseToken
    public Result<ProjectDetail> getProjectDetailById(@PathVariable("projectId") Long projectId){
		SysUser manager = SecurityUtils.getLoginUser().getUser();
        Result<ProjectDetail> result = cietacApi.getProjectDetailById(manager.getMobile(),projectId);
        return result;
    }

    /**
     * 通过项目id获取项目费用列表
     * @return
     */
    @ApiOperation("通过项目id获取项目费用列表")
    @GetMapping(value = "/projectExpenseDetailById/{projectId}")
    @UseToken
    public Result<Object> getProjectExpenseDetailById(@PathVariable("projectId") Long projectId, int page, int size){
        SysUser manager = SecurityUtils.getLoginUser().getUser();
        Result<Object> result = cietacApi.getProjectExpenseDetailById(manager.getMobile(),projectId,page,size);
        return result;
    }
    /**
     * 提交缴费凭证
     * @return
     */
    @ApiOperation("提交缴费凭证")
    @UseToken
    @PostMapping(value = "/submitPaymentVoucher/{projectId}")
    Result<Object> submitPaymentVoucher(@PathVariable("projectId") Long projectId, MultipartFile file){
		SysUser manager = SecurityUtils.getLoginUser().getUser();
        Result<Object> result = cietacApi.submitPaymentVoucher(manager.getMobile(),projectId,file);
        return result;
    };


}
